package org.openbravo.client.application.navigationbarcomponents;

import java.util.List;
import javax.inject.Inject;
import org.openbravo.client.application.MenuManager;
import org.openbravo.client.application.MenuManager.MenuOption;
import org.openbravo.client.kernel.BaseTemplateComponent;

/**
 * Provides a widget to open a classic view from the database.
 * 
 * @author mtaal
 */
public class ApplicationMenuComponent extends BaseTemplateComponent {
	@Inject
	private MenuManager menuManager;

	public String getLabel() {
		return "UINAVBA_APPLICATION_MENU";
	}
	
	public String getMenuName() {
		return this.getComponentTemplate().getName();
	}
	
	// creates the menu items on the basis of the hierarchical tree
	public List<MenuOption> getRootMenuOptions() {
		String name = this.getMenuName();
		List<MenuOption> children = menuManager.getMenu().getChildren();
		for (MenuOption m : children) {
			if (m.getMenu().getName().equals(name)) {
				return m.getChildren();
			}
		}
		return null;
	}
}
